﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class DictionaryDAL
    {
        public string tablename
        {
            get { return "SysDictionary"; }
        }
        public Dictionary<string, bool> PKName
        {
            get
            {
                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("ID", true);
                return dic;
            }
        }
        #region 绑定下拉框
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <returns></returns>
        public List<SysDictionary> sb(string type, int i)
        {
            List<dynamic> type1 = EnumHelperDic.EnumListDic<EnumSelectType>(i, "请选择");
            for (int b = 0; b < type1.Count; b++)
            {
                if (type1[b].text == type)
                {
                    return DictionaryList(type1[b].text);
                }

            }
            return null;

        }
        #endregion
       
        #region 根据类型获取字典集合
        /// <summary>
        /// 根据类型获取字典集合
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<SysDictionary> DictionaryList(string type)
        {
            SqlParameter[]
                Parameter = new SqlParameter[]{
                    new SqlParameter("@Dictionary_Type",type)
                };
            string Sql = Common.GetTable<SysDictionary>(tablename, Parameter);
            DataTable dt = Common.GetDataSet(Sql);


            List<SysDictionary> Dictionary = new List<SysDictionary>();
            foreach (DataRow item in dt.Rows)
            {
                SysDictionary Dictionary1 = new SysDictionary();
                foreach (var i in Dictionary1.GetType().GetProperties())
                {
                    i.SetValue(Dictionary1, item[i.Name]);
                }
                Dictionary.Add(Dictionary1);
            }
            return Dictionary;
        }
        #endregion
    }
}
